package org.dairy.farms.nandana.web.controller;

import org.dairy.farms.model.Expense;
import org.dairy.farms.model.ExpenseType;
import org.dairy.farms.model.LivestockExpense;
import org.dairy.farms.nandana.core.logic.ExpenseManagementLogic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: gduggirala
 * Date: Aug 1, 2011
 * Time: 12:14:23 PM
 */
@Controller
public class ExpenseController {
    private static final Logger logger = LoggerFactory.getLogger(ExpenseController.class);
    @Autowired
    private ExpenseManagementLogic expenseManagementLogic;

    @RequestMapping(value="/expense/getLivestockExpenseTypes",method = RequestMethod.GET)
    public void getLivestockExpenseTypes(Model model){
        List<ExpenseType> liveStockExpenseTypeList = expenseManagementLogic.getExpenseTypes(ExpenseType.EXPENSE_TYPE_OF_LIVESTOCK);
        model.addAttribute("liveStockExpenseTypeList",liveStockExpenseTypeList);
    }

    @RequestMapping(value="/expense/getFarmExpenseTypes",method = RequestMethod.GET)
    public void getFarmExpenseTypes(Model model){
        List<ExpenseType> farmExpenseTypeList = expenseManagementLogic.getExpenseTypes(ExpenseType.EXPENSE_TYPE_OF_FARM);
        model.addAttribute("farmExpenseTypeList",farmExpenseTypeList);
    }

    @RequestMapping(value="/expense/getPersonExpenseTypes",method = RequestMethod.GET)
    public void getPersonExpenseTypes(Model model){
        List<ExpenseType> personExpenseTypeList = expenseManagementLogic.getExpenseTypes(ExpenseType.EXPENSE_TYPE_OF_PERSON);
        model.addAttribute("personExpenseTypeList",personExpenseTypeList);
    }

    @RequestMapping(value="/expense/getLivestockExpenses",method = RequestMethod.GET)
    public void getLivestockExpenses(@RequestParam(value="id",required = true)Long livestockId,Model model,
                              @RequestParam(value="page", required = true) int page,
                              @RequestParam(value="start", required = true) int start,
                              @RequestParam(value="limit", required = true) int limit){
        List<Expense> livestockExpenseList = expenseManagementLogic.getLivestockExpenses(livestockId,page,start,limit);
        model.addAttribute("livestockExpensesList",livestockExpenseList);
    }

    @RequestMapping(value="/expense/getAllLivestockExpenses",method = RequestMethod.GET)
    public void getAllLivestockExpenses(@RequestParam(value="id",required = true)Long livestockId,Model model){
        List<Expense> livestockExpenseList = expenseManagementLogic.getLivestockExpenses(livestockId);
        model.addAttribute("livestockExpensesList",livestockExpenseList);
    }
}
